<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.org/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/resources/layui/css/layui.css}">
</head>
<body>
<script src="/resources/layui/layui.js"></script>
<script type="text/javascript" src="/resources/js/jquery-1.12.3.min.js"></script>
<script th:inline="none">
    layui.use(['layer','form','table'],function(){
        var layer=layui.layer,
            form=layui.form,
            table=layui.table,
            $=layui.jquery;
            var id=$("#vehid").val();
            var frontimg="";
            $.ajax({
                type:"get",
                url:"/vehiclefiles/selecctVehicleById",
                data:{vehid:id},
                success:function(resp){
                    console.log(resp.data.vehiclefile.frontimg);
                    frontimg=resp.data.vehiclefile.frontimg;
                    $("#div1").append("<img src='"+frontimg+"' id='show' width='500px' height='300px'>")
                }
            });
    });
    function preview(){
        var fileReader=new FileReader;
        var file = document.getElementById("carimg1").files[0];
        fileReader.readAsDataURL(file);
        fileReader.onload=(function(e){
            document.getElementById("show").src=this.result;
        });
    }
</script>
<form class="layui-form" action="/vehiclefiles/updateImgById" method="post" enctype="multipart/form-data" id="form1">
    <input type="hidden" id="vehid" name="id">
    <div class="layui-form-item">
        <div class="layui-input-inline" id="div1">

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">修改车辆图片点这里：</label>
        <div class="layui-input-inline">
            <input type="file" name="carimg" id="carimg1" required lay-verify="required"
                   placeholder="修改车辆图片" autocomplete="off" class="layui-input"
                   onchange="preview()">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="submit" class="layui-btn" value="确定">
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>
</html>